package com.example.demo4.utils;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBConnection {
    private String FileName;
    private int DBType;
    private Connection conn;
    private String MYSqlDriver;
    private String MySqlUrl;
    public DBConnection() {
        conn = null;
    }
    //根据数据库类型创建数据库连接,此处默认类型为1:MySQL
    public Connection getConn() {
        DBType = 1;
        switch(DBType){
            case 1:return (getConnection());
            default:return null;
        }
    }
    //
    //创建数据库连接
    public Connection getConnection() {
        try {
            MYSqlDriver = "com.mysql.jdbc.Driver";
            MySqlUrl = "jdbc:mysql://localhost:3306/test";
            Class.forName(MYSqlDriver).newInstance();
            conn = DriverManager.getConnection(MySqlUrl, "root", "123123");
        }catch (Exception e) {
        }
        return conn;
    }
}
